﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.ComponentModel.DataAnnotations;

namespace Sitecore.Models
{
    public class Author : IAssignable
    {
        [Required]
        [StringLength(50, MinimumLength = 1)]
        public string FirstName { get; set; }

        [Required]
        [StringLength(50, MinimumLength = 1)]
        public string LastName { get; set; }

        public void AssignTo(object domain)
        {
            if (domain is DataProject.Author)
            {
                DataProject.Author author = domain as DataProject.Author;
                author.FName = this.FirstName;
                author.LName = this.LastName;
            }
            else throw new NotSupportedException("not valid domain type");
        }

        public static Author FromDbModel(DataProject.Author author) 
        {
            Author _thisAuthor = new Author();
            _thisAuthor.FirstName = author.FName;
            _thisAuthor.LastName = author.LName;
            return _thisAuthor;
        }
    }
}